#ifndef SERIALDIALOG_H
#define SERIALDIALOG_H
#include "ui_qserial.h"
#include <QDialog>
#include <QTimer>

#include <unistd.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>

#include "readthread.h"
#include "writethread.h"

const int speedArr[] = { B300,B1200,B2400,B4800,B9600,B19200,B38400,B57600,B115200 };
const int nameArr[] = { 300,1200,2400,4800,9600,19200,38400,57600,115200 };

class SerialDialog : public QDialog, public Ui::SerialDialog
{
    Q_OBJECT
    public:
	SerialDialog(QWidget *parent = 0);
	
	void GetSerialAttr();
	void RestoreSerialPort();
	bool SetSerialAttr(int,int,int,int,int);
	
	ReadThread* m_readThread;
	WriteThread* m_writeThread;
	
    private:
	QString m_serialName;
	QString m_sendContent;
	int m_serialRD;
	int m_serialWR;
	struct termios m_origIOS;
	bool m_showInHex;
	bool m_sendHex;
	QByteArray m_dataArray;
	QTimer m_autoSendTimer;


        fd_set m_writeSet;
	
    public slots:
	bool OpenSerialPort(bool open = true);
	void GetSerialPort(const QString& text);
	void SetSerialPortAttr(QString);
	void DataAvailable(char*,int);
	void CloseSerialPort();
        void StartSendData( int m_serial, QByteArray m_dataArray);
	void SendData();
	void SetDisplayMode(int);
	void SetSendMode(int);
	void AutoSend(int);

protected:
    void changeEvent(QEvent *e);
    bool  eventFilter(QObject *obj, QEvent *event);


private slots:

    void on_close_clicked();
};
#endif

